package test;

/**
 * description:
 * author:zt
 * date:2021-08-15
 */
public class intToIP {
    public static void main(String[] args) {
        //ip转int
        String ip = "10.0.3.193";
        int res = 0;
        String[] s = ip.split("\\.");
        for (int i = 0; i < s.length; i++) {
            res = res << 8 | Integer.valueOf(s[i]);
        }
        System.out.println(res);

        //int转ip
        int i = 167773121;
        String ans = "";
        int[] tmp = new int[4];
        for (int j = 0; j < 4; j++) {
            int k = i & 255;
            i >>= 8;
            tmp[j] = k;
        }
        for (int j = tmp.length - 1; j >= 0; j--) {
            if (j==0) ans+= String.valueOf(tmp[i]);
            else ans += String.valueOf(tmp[j])+".";
        }
        System.out.println(ans);
    }
}
